package com.handinfo.android.ui.window;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWInputBox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UIFriend implements IUIWindows{
	private DWFrame m_fd_frame = null;
	private DWTitle m_fd_title = null;
	private DWImageBox m_fd_close = null;
	private Bitmap m_bm_close = null;
	private DWBackground m_fd_background = null;
	private DWTextbox m_fd_name = null;
	private DWInputBox m_fd_namein = null;
	private DWButton m_fd_button = null;
	private Bitmap m_bm_button = null;
	private Bitmap m_bm_buttonDown = null;
	private boolean flag = false;
	

	private void addFriend(){
		if(DWGameManager.AdpaterType == 2){
			m_fd_frame = new DWFrame(DWGameManager.Screen_Width*3/8, DWGameManager.Screen_Height/4);
		}else{
			m_fd_frame = new DWFrame(300, 120);
		}
		m_fd_frame.setNearAnchor(UISocial.m_si_fram, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_fd_frame.setClickClose(false);
		m_fd_title = new DWTitle("添加好友", m_fd_frame);
		//关闭窗口
		m_fd_close = new DWImageBox(m_bm_close);
		m_fd_close.setTouchZoomIn(20, 20);
		m_fd_close.setNearAnchor(m_fd_title, Tools.RIGHT_TOP,Tools.RIGHT_TOP, 0, 0);
		//背景
		m_fd_background = new DWBackground(m_fd_frame.getShowWidth(),m_fd_frame.getShowHeight());
		m_fd_background.setNearAnchor(m_fd_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
		//玩家姓名显示
		m_fd_name = new DWTextbox("玩家姓名");
		if(DWGameManager.AdpaterType == 2){
			m_fd_name.setNearAnchor(m_fd_title, Tools.LEFT_TOP, Tools.LEFT_TOP, DWGameManager.Screen_Width*1/80, DWGameManager.Screen_Height/12);
		}else{
			m_fd_name.setNearAnchor(m_fd_title, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 40);
		}
		//玩家姓名输入
		if(DWGameManager.AdpaterType == 2){
			m_fd_namein = new DWInputBox(DWGameManager.Screen_Width*15/80, m_fd_name.getShowHeight(), m_fd_frame);
			m_fd_namein.setNearAnchor(m_fd_name, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 10, 0);
		}else{
			m_fd_namein = new DWInputBox(150, m_fd_name.getShowHeight(), m_fd_frame);
			m_fd_namein.setNearAnchor(m_fd_name, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 120, 0);
		}
		
		//确认按钮
		m_fd_button = new DWButton("确定", m_bm_button);
		m_fd_button.setDownImage(m_bm_buttonDown);
		if(DWGameManager.AdpaterType == 2){
			m_fd_button.setNearAnchor(m_fd_frame, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, 0, 0);
		}else{
			m_fd_button.setNearAnchor(m_fd_title, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 100, 80);
		}
		
		m_fd_frame.addControl(m_fd_background);
		m_fd_frame.addControl(m_fd_title);
		m_fd_frame.addControl(m_fd_close);
		m_fd_frame.addControl(m_fd_name);
		m_fd_frame.addControl(m_fd_namein);
		m_fd_frame.addControl(m_fd_button);
		DWControlsManager.getInstance().addControl(m_fd_frame);
		
		//关闭窗口监听
		m_fd_close.addListener(new DWListener() {
			
			public void OnDoubleClick() {
			}
			
			public void OnClick() {
				UIWindows.getInstance().m_friend.close((byte)0);
			}
		});
		
		//添加好友
		m_fd_button.addListener(new DWListener() {
			
			public void OnDoubleClick() {
			}
			
			public void OnClick() {
				UIWindows.getInstance().m_friend.close((byte)0);
				DWGameManager.getInstance().getSendMessage().sendSocialAddForName(UISocial.SOCIAL_TYPE_FRIEND, m_fd_namein.getText().toString());
			}
		});
	
	
		
	}
	public void init() {
		m_bm_close = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");
		m_bm_button = UIWindows.createImage("/img/newui/anniu_2.gnp");
		m_bm_buttonDown = UIWindows.createImage("/img/newui/anniu_2ax.gnp");
	}

	public void open(byte index) {
		if(flag == false){
			addFriend();
			flag = true;
		}else {
			if(m_fd_frame != null){
				DWControlsManager.getInstance().addControl(m_fd_frame);
			}else{
				return;
			}
			
		}
		
	}

	public void close(byte index) {
		flag = false;
		DWControlsManager.getInstance().removeControl(m_fd_frame);
		
	}

	public void dispose() {
	
	}
	public void logic()
	{
		// TODO Auto-generated method stub
		
	}

}
